<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    @dialog-close="dialogClose"
    :dialogWidth="dialogWidth"
  >
    <template #searchPanel>
      <search-panel
        :addPer="authConfig.add"
        :selectPer="authConfig.query"
        addTitle="新增报价单"
        @insert="add"
        @search="search"
        :showSearchButton="true"
        :showAddButton="true"
        :showExportButton="true"
        @export="handleDataExport('Quote', '报价单')"
      >
        <job-shop v-model="searchOptions.storeId" placeholder="所属门店" />
        <el-input
          v-model="searchOptions.quoteId"
          clearable
          placeholder="工单编号"
          style="width: 200px"
        />
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
        @row-dblclick="rowDblclick"
      >
        <template #action="{ row }">
          <i
            class="el-icon-edit"
            title="编辑"
            style="cursor: pointer"
            v-permission="authConfig.edit"
            @click="handleDataUpdateEdit(row, '编辑')"
          ></i>
          <i
            class="el-icon-delete"
            title="删除"
            style="color: red; margin-left: 20px; cursor: pointer"
            v-permission="authConfig.del"
            @click="handleDataDelete(row)"
          ></i>
        </template>
      </data-table>
    </template>
    <template #dialog>
      <dialog-view-detail
        :workOrderId="selectRow.id"
        :workOrderType="4"
        @close="dialogCloseEv"
      />
    </template>
  </base-layout>
</template>
<script>
import {
  quoteList,
  addQuote,
  deleteQuote,
  getQuoteById,
  editQuote,
} from "@/api/after-sale/workOrderManage/quotation";
import baseMixin from "@/mixins/base";
import { JobShop } from "@/components/index";
import DialogViewDetail from "../view/index.vue";
import { exportExcel } from '@/utils'
export default {
  components: { JobShop, DialogViewDetail },
  mixins: [
    baseMixin({
      findData: quoteList,
      addData: addQuote,
      deleteData: deleteQuote,
      dataName: ["content", "totalRecords"],
      isAdd: false,
      findDataById: getQuoteById,
      updateData: editQuote,
      idName: "id",
    }),
  ],
  data() {
    return {
      authConfig: {
        query: 'quote:page',
        add: 'quote:save',
        edit: 'quote:update',
        del: 'quote:del',
      },
      dialogVisible: false,
      dialogWidth: "1200px",
      tableColumnAttributes: [
        { name: "所属门店", value: "storeName", type: "text", width: 200 },
        { name: "工单编号", value: "workOrderCode", type: "text", width: 150 },
        { name: "单据日期", value: "receiptsTime", type: "text", width: 150 },
        { name: "车牌号", value: "licensePlateNumber", type: "text", width: 150 },
        { name: "项目总数", value: "projectNum", type: "text" },
        { name: "接待人员", value: "receptionName", type: "text", width: 150 },
        { name: "工单报价金额", value: "shouldAmount", type: "text", width: 120 },
        { name: "工单备注", value: "remark", type: "text", width: 150 },
        { name: "录入时间", value: "createTime", type: "text", width: 200 },
      ],
    };
  },
  methods: {
    rowDblclick(row) {
      this.selectRow = row;
      this.dialogVisible = true;
      this.dialogTitle = "工单详情";
    },
    dialogCloseEv() {
      this.dialogClose();
      this.setTableData();
    },
    search(form) {
      // this.searchOptions = {
      //   quoteId: form.quoteId,
      //   storeId: form.storeId,
      // };
      this.currentPage = 1;
      this.setTableData();
    },
    add() {
      this.$router.push({ path: "/workOrderManage/create-quotation" });
    },
    handleDataUpdateEdit(row, type) {
      this.$router.push({
        path: "/workOrderManage/edit-quotation",
        query: { id: row.id },
      });
    },
  },
};
</script>
